package com.ganzalang.gmall.designstrategy.service.impl;

import com.ganzalang.gmall.designstrategy.discount.calculate.DiscountCalculator;
import com.ganzalang.gmall.designstrategy.discount.calculate.DiscountCalculatorSelector;
import com.ganzalang.gmall.designstrategy.dto.DiscountDTO;
import com.ganzalang.gmall.designstrategy.enums.DiscountTypeEnum;
import com.ganzalang.gmall.designstrategy.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 测试service的实现类
 * @author: ganzalang
 */
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private DiscountCalculatorSelector discountCalculatorSelector;

    @Override
    public void test() {
        List<DiscountDTO> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            DiscountDTO discountDTO = new DiscountDTO();
            discountDTO.setId(i);
            discountDTO.setCode("code" + String.valueOf(i));
            discountDTO.setType(i);
            list.add(discountDTO);
        }

        for (DiscountDTO discountDTO : list) {
            DiscountCalculator discountCalculator = discountCalculatorSelector.create(DiscountTypeEnum.getByType(discountDTO.getType()));
            discountCalculator.calculate();
        }
    }
}
